package com.jelly.mina.chat;

/**
 * 协议命令
 * 
 * @author Jelly
 * 
 */
public class ChatCommand {
	public static final int LOGIN = 0;// 登录

	public static final int QUIT = 1;// 退出

	public static final int BROADCAST = 2;// 广播

	private final int num;

	public ChatCommand(int num) {
		this.num = num;
	}

	public int toInt() {
		return num;
	}

	/* 
     *  
     */
	public static ChatCommand valueOf(String s) {
		s = s.toUpperCase();
		if ("LOGIN".equals(s)) {
			return new ChatCommand(LOGIN);
		}
		if ("QUIT".equals(s)) {
			return new ChatCommand(QUIT);
		}
		if ("BROADCAST".equals(s)) {
			return new ChatCommand(BROADCAST);
		}

		throw new IllegalArgumentException("Unrecognized command: " + s);
	}
}
